﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using CommomFunctions;
using System.Windows.Controls;
using System.Windows.Media;

namespace Árvore_Binária_de_Pesquisa
{
    
    public enum MenuClicked
    {
        removePredecessor,
        removeSuccessor
    }

    public class Menus
    {
        /// <summary>
        /// Indicates if it is to replace the root by its predecessor or not
        /// </summary>
        private static bool removePred = false;
        
        public static bool removePredecessor
        {
            get { return removePred; }
            set { removePred = value; }
        }

        /// <summary>
        /// Updates the "IsChecked" information of the MenuItems "rp" and "rs" 
        /// Updates if the root will be replaced by its predecessor node or not
        /// </summary>
        /// <param name="rp"></param>
        /// <param name="rs"></param>
        public static void removePredecessor_Click(MenuItem rp, MenuItem rs)
        {
            rp.IsChecked = true;
            rs.IsChecked = false;
            removePredecessor = true;
        }

        public static void removeSuccessor_Click(MenuItem rp, MenuItem rs)
        {
            rp.IsChecked = false;
            rs.IsChecked = true;
            removePredecessor = false;
        }

        /// <summary>
        /// Visit the nodes accolording to the traversal "tc" chosen.
        /// </summary>
        public static void visitNodes(TraversalClicked tc, ControlVariables cv)
        {
            TraversalPositions tp = new TraversalPositions();

            string sentence = "";
            switch (tc)
            {
                case TraversalClicked.preOrderRight: tp = Traversals.preOrderRight_Click();
                    sentence = "Percorrendo caminho pré-fixado à direita\n\t (raiz - dir - esq)";
                    break;
                case TraversalClicked.inOrderRight: tp = Traversals.inOrderRight_Click();
                    sentence = "Percorrendo caminho central à direita\n\t (dir - raiz - esq)";
                    break;
                case TraversalClicked.postOrderRight: tp = Traversals.postOrderRight_Click();
                    sentence = "Percorrendo caminho pós-fixado à direita\n\t (dir - esq - raiz)";
                    break;
                case TraversalClicked.preOrderLeft: tp = Traversals.preOrderLeft_Click();
                    sentence = "Percorrendo caminho pré-fixado à esquerda\n\t (raiz - esq - dir)";
                    break;
                case TraversalClicked.inOrderLeft: tp = Traversals.inOrderLeft_Click();
                    sentence = "Percorrendo caminho central à esquerda\n\t (esq - raiz - dir)";
                    break;
                case TraversalClicked.postOrderLeft: tp = Traversals.postOrderLeft_Click();
                    sentence = "Percorrendo caminho pós-fixado à esquerda\n\t (esq - dir - raiz)";
                    break;
            }

            cv.writeTrace(sentence, Brushes.SpringGreen);
            cv.animateTraversal(tp.positions, tp.addNodeVisited);
        }

        internal static void disableMenuItems(MenuItem[] MenuItems)
        {
            foreach (MenuItem m in MenuItems)
            {
                m.IsEnabled = false;
            }
        }

        internal static void enableMenuItems(MenuItem[] MenuItems)
        {
            foreach (MenuItem m in MenuItems)
            {
                m.IsEnabled = true;
            }
        }
    }
}
